package com.sinsoft.monitorDemo.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sinosoft.framework.core.common.utils.ajax.ResponseData;
import com.sinsoft.monitorDemo.dao.ProcessInfoDao;
import com.sinsoft.monitorDemo.entity.ProcessInfo;

@Controller
@RequestMapping("/processInfo")
public class ProcessInfoController {
	
	/**
	 * 得到当前时间之前一段时间的的CPU信息
	 * @return
	 */
	@RequestMapping(value = "/getProcessInfoList", method = RequestMethod.POST)
	@ResponseBody
	public ResponseData getProcessinfoList(HttpServletRequest request){
		ProcessInfoDao dao = new ProcessInfoDao();
		String ip = request.getParameter("ip");
		List<ProcessInfo> processInfos = dao.getProcessInfoList(ip);
		ResponseData responseData = new ResponseData(true, processInfos);
		return responseData;	
	}
	
	/**
	 * 得到最新的CPU信息
	 * @return
	 */
	@RequestMapping(value = "/getNewProcessinfo", method = RequestMethod.POST)
	@ResponseBody
	public ResponseData getNewPreocessinfo(HttpServletRequest request){
		ProcessInfoDao dao = new ProcessInfoDao();
		String ip = request.getParameter("ip");
		ProcessInfo processInfo = dao.getNewProcessInfo(ip);
		ResponseData responseData = new ResponseData(true, processInfo);
		return responseData;	
	}
}
